<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/home/config.php';

$array_return = array();
$array_return['status'] = 0;
$array_return['html'] = '';

$com_post_id = getValue('com_post_id','int','POST',0);
$com_type = getValue('com_type','str','POST','',2);
$com_email = getValue('com_email','str','POST','',2);
$com_name = getValue('com_name','str','POST','',2);
$com_content = getValue('com_content','str','POST','',2);
if($com_email == '' || $com_email == '' || $com_name == '' || $com_content == '') {
   $array_return['html'] = 'Thiếu dữ liệu gửi đi';
}else {
   $db_in_cmt = new db_execute('INSERT INTO comments(com_content,com_name,com_email,com_post_id,com_type,com_date,com_date_feedback)
                                             VALUES("'.$com_content.'","'.$com_name.'","'.$com_email.'",'.$com_post_id.',"'.$com_type.'",'.time().','.time().')');

   if($db_in_cmt->total) {
      setcookie('comment_name',$com_name,time() + 86400,'/');
      setcookie('comment_email',$com_email,time() + 86400,'/');
      $array_return['status'] = 1;
      $array_return['html'] = '<div class="comment_item">
                                 <img src="/themes/img/avatar_guest.jpg" alt="avatar guest comment" />
                                 <p class="cmt_name"><strong>'.$com_name.'</strong></p>
                                 <p class="cmt_content">'.$com_content.'</p>
                                 <p class="cmt_meta">
                                    <span class="cmt_like">Thích <i class="icon_like"></i> <span>0</span></span>
                                    <span class="cmt_date">vừa xong</span>
                                 </p>
                              </div>';
   }else {
      $array_return['status'] = 0;
      $array_return['html'] = 'Lỗi không xác định. Vui lòng thử lại sau.';
   }
}

die(json_encode($array_return));
?>